home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
3DMAZE
/
MAZE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-16
|
6KB
|
261 lines
/* --- This source is for Lightspeed C 3.0 or greater --- */
/* InitTheMenus initializes the menus */
/* About Modal Dialog */
/* P_D_Maze Window */
/* HandleTheMenus Handle the menu selection */
/* Resource file to use is Maze.RSRC */
/* RMaker file to use is Maze.R */
/* Maze.c Main program */
/* MacTraps use this LSC library from the Mac Libraries folder */
/* strings use this LSC library from the Libraries folder */
/* ==============================
Program name: Maze.c
Function: This is the main module for this program.
History: 2/15/91 Original by Prototyper.
================================= */
/* *********************************** */
/* These are the other includes for general routines */
#include "Strings.h"
extern char * strcpy(Str255 *, char *);
/* *********************************** */
#define TRUE 1
#define FALSE 0
#define NIL 0
/* *********************************** */
/* External routines that are called */
extern void InitMyMenus(void);
extern void HandleMenu(char *doneFlag, short theMenu, short theItem, TEHandle *theInput);
#include "About.h"
#include "P_D_Maze.h"
/* ====================================== */
/* ====================================== */
void main(void);
/* ====================================== */
void main()
{
char doneFlag;
char Is_A_Dialog;
char stillInGoAway;
char ch;
short code;
short theMenu,theItem;
short chCode;
long mResult;
WindowPtr whichWindow;
EventRecord myEvent;
TEHandle theInput;
Rect tempRect,OldRect;
Point myPt;
GrafPtr SavePort;
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent,0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(NIL);
InitCursor();
doneFlag = FALSE;
InitMyMenus();
theInput = NIL;
Init_P_D_Maze();
Open_P_D_Maze(&theInput);
do
{
if (theInput != NIL)
TEIdle(theInput);
SystemTask();
if (GetNextEvent(everyEvent, &myEvent))
{
code = FindWindow(myEvent.where, &whichWindow);
switch (myEvent.what)
{
case mouseDown:
if (code == inMenuBar)
{
mResult = MenuSelect(myEvent.where);
theMenu = HiWord(mResult);
theItem = LoWord(mResult);
HandleMenu(&doneFlag,theMenu,theItem,&theInput);
}
if ((code == inDrag)&&(whichWindow != NIL))
{
tempRect = screenBits.bounds;
SetRect(&tempRect, tempRect.left + 10, tempRect.top + 25, tempRect.right - 10, tempRect.bottom - 10);
DragWindow(whichWindow, myEvent.where, &tempRect);
}
if (code == inGrow)
{
SetPort(whichWindow);
myPt = myEvent.where;
GlobalToLocal(&myPt);
OldRect.left = whichWindow->portRect.left;
OldRect.right = whichWindow->portRect.right;
OldRect.top = whichWindow->portRect.top;
OldRect.bottom = whichWindow->portRect.bottom;
SetRect(&tempRect,15,15,(screenBits.bounds.right - screenBits.bounds.left), (screenBits.bounds.bottom - screenBits.bounds.top) - 20);
mResult = GrowWindow(whichWindow, myEvent.where, &tempRect);
SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), TRUE);
SetPort(whichWindow);
SetRect(&tempRect, 0, myPt.v - 15, myPt.h + 15, myPt.v + 15);
EraseRect(&tempRect);
InvalRect(&tempRect);
SetRect(&tempRect, myPt.h - 15, 0, myPt.h + 15, myPt.v + 15);
EraseRect(&tempRect);
InvalRect(&tempRect);
DrawGrowIcon(whichWindow);
}
if (code == inGoAway)
{
stillInGoAway = TrackGoAway(whichWindow,myEvent.where);
if (stillInGoAway == TRUE)
{
switch (GetWRefCon(whichWindow))
{
case 1:
Close_P_D_Maze(whichWindow,&theInput);
break;
}
}
}
if (code == inContent)
{
if (whichWindow != FrontWindow())
{
SelectWindow(whichWindow);
}
else
{
SetPort(whichWindow);
switch (GetWRefCon(whichWindow))
{
case 1:
Do_P_D_Maze (&myEvent,&theInput );
break;
}
}
}
if (code == inSysWindow)
{
SystemClick(&myEvent, whichWindow);
}
if ((code == inZoomIn) || (code == inZoomOut))
{
if (whichWindow != NIL)
{
SetPort(whichWindow);
myPt = myEvent.where;
GlobalToLocal(&myPt);
if (TrackBox(whichWindow, myPt, code) == TRUE)
{
ZoomWindow(whichWindow, code, TRUE);
SetRect(&tempRect, 0, 0, 32000, 32000);
EraseRect(&tempRect);
InvalRect(&tempRect);
}
}
}
break;
case keyDown:
case autoKey:
ch = myEvent.message & charCodeMask;
mResult = MenuKey(ch);
theMenu = HiWord(mResult);
theItem = LoWord(mResult);
if (theMenu != 0)
HandleMenu(&doneFlag, theMenu, theItem, &theInput);
break;
case updateEvt:
whichWindow = (WindowPtr)myEvent.message;
GetPort(&SavePort);
BeginUpdate(whichWindow);
SetPort(whichWindow);
switch (GetWRefCon(whichWindow))
{
case 1:
UpDate_P_D_Maze(whichWindow);
break;
}
EndUpdate(whichWindow);
SetPort(SavePort);
break;
case diskEvt:
if (HiWord(myEvent.message) != 0)
{
myEvent.where.h = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - (304 / 2);
myEvent.where.v = ((screenBits.bounds.bottom - screenBits.bounds.top) / 3) - (104 / 2);
InitCursor();
theItem = DIBadMount(myEvent.where, myEvent.message);
}
break;
case app1Evt:
if (((HiWord(myEvent.message) == 1) && (LoWord(myEvent.message)) ==1))
Open_P_D_Maze(&theInput);
if (((HiWord(myEvent.message) == 2) && (LoWord(myEvent.message)) ==1))
Close_P_D_Maze((WindowPtr)-1,&theInput);
break;
case activateEvt:
if ((whichWindow != NIL) && (myEvent.modifiers & activeFlag))
{
SelectWindow(whichWindow);
}
break;
default:
break;
}
}
}
while (doneFlag == FALSE);
}